﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BrainMatch
{
    public partial class DatabaseConfigDialog : Form
    {
        public string ServerName
        {
            get
            {
                return textBox1.Text;
            }
        }

        public string Database
        {
            get
            {
                return textBox2.Text;
            }
        }
        public string Username
        {
            get
            {
                return textBox3.Text;
            }
        }
        public string Password
        {
            get
            {
                return textBox4.Text;
            }
        }
        public DatabaseConfigDialog()
        {
            InitializeComponent();
        }

        private void DatabaseConfigDialog_Load(object sender, EventArgs e)
        {
            textBox1.Text = Properties.Settings.Default.ServerName;
            textBox2.Text = Properties.Settings.Default.Database;
            textBox3.Text = Properties.Settings.Default.Username;
            textBox4.Text = Properties.Settings.Default.Password;
            textBox5.Text = Properties.Settings.Default.rar;
            textBox6.Text = Properties.Settings.Default.Exporter;
            eggdir.Text = Properties.Settings.Default.ReportDirectory;
            txtout.Text = Properties.Settings.Default.OutTextDirectory;
            docdir.Text = Properties.Settings.Default.DocDirectory;
            swpdir.Text = Properties.Settings.Default.TxtDocDirectory;
            reportcmd.Text = Properties.Settings.Default.Reporter;
        }

        private void OnSave(object sender, EventArgs e)
        {
            Properties.Settings.Default.ServerName = textBox1.Text;
            Properties.Settings.Default.Database=textBox2.Text;
            Properties.Settings.Default.Username=textBox3.Text;
            Properties.Settings.Default.Password=textBox4.Text;
            Properties.Settings.Default.rar=textBox5.Text;
            Properties.Settings.Default.Exporter = textBox6.Text;

             Properties.Settings.Default.ReportDirectory=eggdir.Text;
             Properties.Settings.Default.OutTextDirectory=txtout.Text;
             Properties.Settings.Default.DocDirectory=docdir.Text;
             Properties.Settings.Default.TxtDocDirectory=swpdir.Text;
             Properties.Settings.Default.Reporter=reportcmd.Text;

            Properties.Settings.Default.Save();
        }

        private void OnTest(object sender, EventArgs e)
        {
            string connect = string.Format(Properties.Settings.Default.DataConnection, textBox1.Text,
                                                                                    textBox2.Text,
                                                                                    textBox3.Text,
                                                                                    textBox4.Text);
            try
            {
                SqlConnection dataconnect = new SqlConnection(connect);
                dataconnect.Open();
                MessageBox.Show("测试成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
